#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QPainter"
#include<config.h>
#include <map_1.h>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
/**********************/
    m_menu.load(GAME_Mainscene_Pic);//加载主界面背景
    MainScene();
    updategame();
    game_exit();

/**********************/
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::MainScene()
{
    //设置窗口尺寸（固定）
    setFixedSize(GAME_WIDTH,GAME_HEIGHT);
    //标题
    setWindowTitle(GAME_TITLE);
    //窗口图标
    setWindowIcon(QIcon(GAME_Icon));
    //主界面按钮

    gamequit_btn->setParent(this);
    gamestart_btn->setParent(this);
    gamestart_btn->setGeometry(500,340,80,35);
    gamestart_btn->show();
    gamequit_btn->setGeometry(500,400,80,35);
    gamequit_btn->show();
    connect(gamequit_btn,SIGNAL(clicked(bool)),this,SLOT(game_exit()));
    connect(gamestart_btn,SIGNAL(clicked(bool)),this,SLOT(game_start()));


    //计时器
     QTimer *_time=new QTimer();
     _time->start(5);
     connect(_time,SIGNAL(timeout()),this,SLOT(updategame()));


}

void MainWindow::updategame()
{

    time_counter++;
    if(map1.m_map1_y>0&&map1.is_used)map1.m_map1_y--;
    update();
}

void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.drawPixmap(0,0,1080,720,m_menu);//  尝试绘制地图场景

   if(map1.is_used) painter.drawPixmap(map1.m_map1_x,map1.m_map1_y,1080,720,map1.m_map1);

}

void MainWindow::game_exit()
{
    QApplication *EXIT;
    EXIT->quit();
}

void MainWindow::game_start()
{
    gamestart_btn->hide();
    gamequit_btn->move(1000,0);
    map1.is_used=true;
    update();















}
